import { Component, OnInit } from '@angular/core';
import { EventManagerService } from 'src/app/services/event-manager.service';
import { OrgCodeItem } from './../models';

@Component({
  selector: 'zepride-date-code-input',
  templateUrl: './date-code-input.component.html',
  styleUrls: ['./date-code-input.component.less', '../org-code-item-panel/org-code-item-panel.component.less']
})
export class DateCodeInputComponent implements OnInit {
  visible: boolean;
  orgItem: OrgCodeItem;
  onAddItemHandle;
  onDelOrgCodeItemHandle;
  constructor(
    private eventSvr: EventManagerService
  ) { }

  ngOnInit(): void {
  }

  addAutoItem(type) {
    this.onAddItemHandle && this.onAddItemHandle(type);
    this.eventSvr.callEvents('groupBoxResize', { action: 'add' });
  }

  delItem() {
    this.onDelOrgCodeItemHandle && this.onDelOrgCodeItemHandle(this.orgItem);
    this.eventSvr.callEvents('groupBoxResize', { action: 'add' });
  }

  selectChange(key, value) {
    let t = new Date();
    this.orgItem[key] = value;

    let tp = [];
    if (this.orgItem.showYear) {
      tp.push(t.getFullYear() + "");
    }
    if (this.orgItem.showMonth) {
      tp.push((t.getMonth() + 1) + "");
    }
    if (this.orgItem.showDay) {
      tp.push(t.getDate() + "");
    }

    this.orgItem.value = tp.join(this.orgItem.separatorChar);
  }

  ok() {
    this.visible = false;
  }

}
